﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;
using l1cs.server.utils;
using l1cs.server.datatables;
using l1cs.server.templates;

namespace l1cs.server.serverpackets
{
    public class S_AuctionBoardRead : ServerBasePacket
    {
        private static Logger _log = Logger.getLogger( typeof( S_AuctionBoardRead ).FullName );
 
        private byte[] _byte = null;

        public S_AuctionBoardRead( int objectId, String house_number )
        {
            buildPacket( objectId, house_number );
        }

        private void buildPacket( int objectId, String house_number )
        {
            int houseid = Convert.ToInt32( house_number );
            L1AuctionBoard auctionBoard = AuctionBoardTable.getInstance().getAuctionBoardTable( houseid );
            writeC( Opcodes.S_OPCODE_SHOWHTML );
            writeD( objectId );
            writeS( "agsel" );
            writeS( house_number ); // アジトの番号
            writeH( 9 ); // 以下の文字列の個数
            writeS( auctionBoard.getHouseName() );  // アジトの名前
            writeS( auctionBoard.getLocation() ); // アジトの位置
            writeS( auctionBoard.getHouseArea().ToString() );  // アジトの広さ
            writeS( auctionBoard.getOldOwner() );  // 以前の所有者
            writeS( auctionBoard.getBidder() );  // 現在の入札者
            writeS( auctionBoard.getPrice().ToString() );  // 現在の入札価格
            writeS( auctionBoard.getDeadline().Month.ToString() ); // 締切月
            writeS( auctionBoard.getDeadline().Day.ToString() ); // 締切日
            writeS( auctionBoard.getDeadline().Hour.ToString() ); // 締切時
        }

        override
        public byte[] getContent()
        {
            if ( _byte == null )
            {
                _byte = getBytes();
            }
            return _byte;
        }

        override
        public String getType()
        {
            return "[S] S_AuctionBoardRead";
        }
    }
}
